
package RPG;

import EntitySystem.Entity;
import Interface.ActionTab;
import Interface.EnemyTab;
import Interface.InventoryTab;
import Interface.SpellTab;
import Interface.Tab;
import java.util.ArrayList;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class ForestScene extends BasicGameState{
    
    private Image forest;
    private Input input;
    private StateBasedGame game;
    private int ID;
    private ArrayList<Entity> entities;
    
    private Image UIbackground;
    private ActionTab actiontab;
    private Tab currenttab;
    //current pane ie. enemy or friendly pane
    
    public ForestScene(int id) throws SlickException{
        ID=id;
        
    }
    
    @Override
    public int getID() {
        return ID;
    }

    @Override
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        game=sbg;
        input=gc.getInput();
        entities=new ArrayList();
        
        forest=new Image("data/battlescenes/forest.png");
        forest = forest.getScaledCopy(gc.getWidth(), gc.getHeight()/2);
        UIbackground = new Image("data/battlescenes/battlescenebackground.png");
        UIbackground = UIbackground.getScaledCopy(gc.getWidth(), gc.getHeight()/2);
        
        actiontab=new ActionTab();
        scaleTab(actiontab);
        currenttab = actiontab;
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics grphcs) throws SlickException {
        forest.draw(0, 0);
        UIbackground.draw(0, gc.getHeight()/2);
        
        drawTab(currenttab);
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        
        if(input.isKeyPressed(Input.KEY_X)){
            currenttab = currenttab.Select();
        }else if(input.isKeyPressed(Input.KEY_Z)){
            currenttab = currenttab.Deselect();
        }else if(input.isKeyPressed(Input.KEY_UP)){
            currenttab.MoveUp();
        }else if(input.isKeyPressed(Input.KEY_DOWN)){
            currenttab.MoveDown();
        }else if(input.isKeyPressed(Input.KEY_LEFT)){
            currenttab.MoveLeft();
        }else if(input.isKeyPressed(Input.KEY_RIGHT)){
            currenttab.MoveRight();
        }
        
        scaleTab(currenttab);
    }

    /*Scales the current image of the tab based on its nature*/
    public void scaleTab(Tab tab){
        if(tab instanceof ActionTab){
            tab.setCurrentImage(tab.getCurrentImage().getScaledCopy(UIbackground.getWidth()/3, UIbackground.getHeight()));
        }else if(tab instanceof SpellTab){
            tab.setCurrentImage(tab.getCurrentImage().getScaledCopy(UIbackground.getWidth()/3, UIbackground.getHeight()));
        }else if(tab instanceof InventoryTab){
            tab.setCurrentImage(tab.getCurrentImage().getScaledCopy(UIbackground.getWidth()/3, UIbackground.getHeight()));
        }else if(tab instanceof EnemyTab){
            tab.setCurrentImage(tab.getCurrentImage().getScaledCopy(forest.getWidth(), forest.getHeight()));
        }
        
    }
    
    /*Draws the current image of the tab based on its nature*/
    public void drawTab(Tab tab){
        if(tab instanceof ActionTab){
            tab.getCurrentImage().draw(UIbackground.getWidth()-UIbackground.getWidth()/3, UIbackground.getHeight());
        }else if(tab instanceof SpellTab){
            tab.getCurrentImage().draw(UIbackground.getWidth()-UIbackground.getWidth()/3, UIbackground.getHeight());
        }else if(tab instanceof InventoryTab){
            tab.getCurrentImage().draw(UIbackground.getWidth()-UIbackground.getWidth()/3, UIbackground.getHeight());
        }else if(tab instanceof EnemyTab){
            tab.getCurrentImage().draw(0, 0);
        }
    }
    
}
